/*
 * @Description:
 * @Author: cgt
 * @Date: 2021-11-23 20:18:17
 * @LastEditors: cgt
 * @LastEditTime: 2021-12-28 18:47:05
 */
export default class Rectangle {
  constructor(x, y, w, h) {
    this.x = x;
    this.y = y;
    this.w = w;
    this.h = h;
  }

  //Check if a point is Inside the rectangle
  contains(point) {
    return point.x >= this.x - this.w &&
          point.x <= this.x + this.w &&
          point.y >= this.y - this.h &&
          point.y <= this.y + this.h
    ;
  }

  //Check if a Rectangle(Range) intersects with this rectangle
  intersects(range) {
    return !(range.x - range.w > this.x + this.w
          || range.x + range.w < this.x - this.w
          || range.y - range.h > this.y + this.h
          || range.y + range.h < this.y - this.h
    );
  }
}